#!/bin/bash

#定义文件变量名称
export jmx_template_file="newbee_auto_stress"
export type=".jmx"
export jmx_file_name="${jmx_template_file}${type}"
export os_type=`uname`
export jmeter_path="/usr/local/apache-jmeter-5.4.1"
echo "开始执行自动化压测"


thread_num_array=(10 20 30)
for num in "${thread_num_array[@]}"
do

	#定义压测文件的变量名称
  export jmx_filename="${jmx_template_file}_${num}${type}"
  export jtl_filename="test_${num}.jtl"
  export web_report_file="web_${num}report"
	
	#前序环境清理
  rm -rf ${web_report_file}
	#准备压测文件源
  cp ${jmx_file_name} ${jmx_filename}

	#循环遍历修改压测线程数
  if [ "${os_type}" == "Linux" ]
  then
      sed -i "s/thread_num/${num}/g" ${jmx_filename}
  fi
	
	#开始执行压测操作

  ${jmeter_path}/bin/jmeter -n -t ${jmx_filename} -l ${jtl_filename}
  ${jmeter_path}/bin/jmeter -g ${jtl_filename} -e -o ${web_report_file}

	#后续环境清理
  rm -rf ${jmx_filename} ${jtl_filename}
		 
done

echo "自动化压测执行结束"
